<template>
  <div class="wrap">
    <div class="title">
      <p class="name">游记</p>
      <p class="decorate">
        ——— <span class="iconfont search-icon">&#xe617;</span> ———
      </p>
      <p class="desc">TRAVELNOTE</p>
    </div>
    <div class="travel-notes-box">
      <swiper ref="mySwiper" :options="swiperOptions">
        <swiper-slide
          v-for="(item1, index1) in travelnoteArr.length / 4"
          :key="index1"
        >
          <ul class="travel-notes-list">
            <a href="##" v-for="(item, index) in travelnoteArr0" :key="index">
              <li>
                <img :src="item.img" alt="" />
                <p class="travel-notes-name">{{ item.title }}</p>
                <p class="travel-notes-author">{{ item.writer }}</p>
                <p class="travel-notes-text">{{ item.content }}</p>
              </li>
            </a>
          </ul>
        </swiper-slide>
        <div class="swiper-pagination" slot="pagination"></div>
      </swiper>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // 同HomeMovement bug
      travelnoteArr: [],
      travelnoteArr0: [],

      swiperOptions: {
        pagination: {
          el: ".swiper-pagination",
          clickable: true,
        },
        loop: true,
        // Some Swiper option/callback...
      },
    };
  },
  computed: {
    swiper() {
      return this.$refs.mySwiper.$swiper;
    },
  },
  mounted() {
    this.swiper.slideTo(1, 1000, false);
    this.$api.HomeTravelnote().then((res) => {
      if (res.data.success === true) {
        this.travelnoteArr = res.data.travelnote;
        var arr = res.data.travelnote;
        for (var i = 0; i < arr.length; i++) {
          arr[i].img =
            "http://iwenwiki.com/api/" + String(arr[i].img).slice(24);
        }
        var n = 0;
        for (var i = 0; i < 4; i++) {
          // for (var k = 0 * 4; k < 4; k++) {  // 有个bug
          this.travelnoteArr0[i] = arr[n];
          n++;
          // }
        }
      }
    });
  },
};
</script>

<style lang="less" scoped>
.wrap {
  width: 1200px;
  margin: 0 auto;
}
.title {
  width: 140px;
  height: 73px;
  margin: 40px auto 0;
  text-align: center;
  .name {
    color: #292929;
    margin-bottom: 5px;
    font-size: 24px;
  }
  .decorate {
    opacity: 0.1;
  }
  .desc {
    color: #292929;
    margin-bottom: 5px;
  }
}
.swiper-container {
  --swiper-pagination-color: #00ff33;
}
.travel-notes-box {
  margin: 50px 0 20px;
}
.travel-notes-list {
  height: 542px;
  li {
    height: 470px;
    border: 1px solid #bababa;
    float: left;
    margin-right: 25px;
    transition: all 0.4s;
    position: relative;
    overflow: hidden;
    img {
      width: 278px;
      height: 380px;
    }
    .travel-notes-name {
      font-size: 16px;
      color: #1b1b1b;
      margin-top: 15px;
      text-align: center;
    }
    .travel-notes-author {
      margin-top: 10px;
      color: #6dc7fa;
      font-size: 12px;
      padding-left: 10px;
    }
  }
  li:hover {
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.2);
    transform: translateY(-2px);
  }
  .travel-notes-text {
    width: 85%;
    position: absolute;
    top: 125px;
    left: 0;
    background-color: rgba(0, 0, 0, 0.5);
    color: #fff;
    padding: 20px;
    transition: all 0.4s;
    margin-left: -100%;
  }
  li:hover .travel-notes-text {
    margin-left: 0;
  }
}
.travel-notes-list > a:nth-of-type(4) li {
  margin-right: 0;
}
</style>